package at.evonfc.data;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.view.View;


public class Cart {

	private static ArrayList<CartDevice> tempDevices = new ArrayList<CartDevice>();
	private static ArrayList<CartDevice> cartDevices = new ArrayList<CartDevice>();
	private static CartDevice cartDevice;
	
	public static void createNewCartDevice(Device device) {
		if(cartDevice != null) {
			if(cartDevice.getBeginDate() == null && cartDevice.getEndDate() == null) {
				tempDevices.remove(cartDevice);
				cartDevices.remove(cartDevice);
			}
		}
		cartDevice = new CartDevice(device);
		tempDevices.add(cartDevice);
	}
	
	public static void setDeviceDates(Calendar beginDate, Calendar endDate) {
		cartDevice.setBeginDate(beginDate);
		cartDevice.setEndDate(endDate);
	}
	
	public static void setDeviceEquipment(List<Equipment> equipment) {
		cartDevice.setEquipments(equipment);
	}
	
	public static void markDeviceAsReserved() {
		cartDevice.setReserved(true);
	}

	public static ArrayList<CartDevice> getCartDevices() {
		return cartDevices;
	}
	
	public static void clear() {
		cartDevices.clear();
	}

	public static boolean hasElements() {
		return !cartDevices.isEmpty();
	}
	
	public static void removeUnused() {
		ArrayList<CartDevice> removeDevices = new ArrayList<CartDevice>();
		for(CartDevice dev : cartDevices) {
			if(dev.getBeginDate() == null) {
				removeDevices.add(dev);
			}
		}
		
		for(CartDevice dev : removeDevices) {
			cartDevices.remove(dev);
		}
	}
	
	public static void removeCartDevice(int index) {
		cartDevices.remove(index);
	}
	
	public static void setActiveCartDevice(CartDevice dev) {
		cartDevice = dev;
	}

	public static CartDevice getActiveCartDevice() {
		return cartDevice;
	}
	
	public static void acceptCartDevice() {
		cartDevices.addAll(tempDevices);
		tempDevices.clear();
	}

	public static void removeCartDevice(CartDevice dev) {
		cartDevices.remove(dev);
	}
}
